var text = [{
  title: '详情', endTime: '申请截止时间', reward: '报酬', deadline: '任务截止期限',
  time: '申请时间', cancel: '取消', report: '报告', finish: '结题',
  submit: ' 查看\n结题申请', back: '返回', del: '提前\n终止', sending: '正在处理', phone: '联系方式：'
}, {
  title: '详情', endTime: '申请截止时间', reward: '报酬', deadline: '任务截止期限',
  time: '申请时间', cancel: '取消', report: '申请', finish: '结题',
  submit: '已提交',  back: '返回', del: '终止', sending: '正在处理', phone: '联系方式：',
}],
modal = [{
  toast: '你已经提交过结题申请啦，耐心等待发布人同意吧~',
  finish: '向发布者申请结题', finish0: '若本次申请被驳回，您仍能重新提交申请。', finish2: '前往结题'
}, {
  toast: '你已经提交过结题申请啦，耐心等待发布人同意吧~',
  finish: '向发布者申请结题', finish0: '若本次申请被驳回，您仍能重新提交申请。',finish2: '前往结题'
}];
var animating, sending;
Page({

  data: {
    hideGroup: true,
    showMask: true,
    sign: false,
  },

  onLoad: function (options) {
    sending = animating = 0;
    let item = JSON.parse(decodeURIComponent(options.content));
    if (item.gmtdead != '0')
      item.deadline = wx.formatTime(new Date(parseInt(item.gmtdead) * 1e3), '/');
    else 
      item.deadline = 0;
    this.setData({
      item: item,
      text: text[wx.lang],
      theme: wx.theme,
    });
  },

  onShow() {
    wx.onShow(this, text[wx.lang].title, wx.theme);
  },

  report() {
    if (animating++) return;
    let sign_up = this.data.item.sign_up
    wx.slide_v(this, ['group1'], wx.system.height, 0, .5, () => {
      this.setData({ hideGroup: true });
      wx._slide_v(this, ['group2'], wx.system.height, 0, () => {
        wx.slide_v(this, ['group2'], 0, 1, 0, () => {
          animating = 0;
        })
      })
    })
    // let data = [];
    // for (let i = 0; i < sign_up.length; ++i) {
    //   sign_up[i].time = wx.formatTime(new Date(parseInt(sign_up[i].gmtcreate) * 1e3), '-');
    //   data.push('card[' + i + ']');
    // }
    // wx.slide_h(this, ['content1'], -1 * wx.system.height, 0, 1, () => {
    //   this.setData({ sign_up: sign_up, sign: true });
    //   wx._slide_v(this, data, wx.system.height * .8, 0, () => {
    //     wx.slide_v(this, data, 0, 1, 0);
    //   })
    // })
  },

  checkApplication() {
    let string = JSON.stringify(this.data.item.submitInfo),
    id = this.data.item.itemInfo.idpracticeitem;
    wx.onHide(this, `../submit/submit?id=${id}&content=${encodeURIComponent(string)}`);
  },
  
  cancel() {
    wx.toast('功能暂未开放')
  },
  
  call(e) {
    wx.makePhoneCall({  
      phoneNumber: e.currentTarget.id,
    })
  },

  back() {
    if (animating++) return;
    wx.slide_v(this, ['group2'], wx.system.height, 0, .5, () => {
      this.setData({ hideGroup: false });
      wx._slide_v(this, ['group1'], wx.system.height, 0, () => {
        wx.slide_v(this, ['group1'], 0, 1, 0, () => {
          animating = 0;
        });
      });
    });
    wx.slide_h(this, ['content2'], wx.system.height, 0, 1, () => {
      this.setData({ sign: false, });
      wx._slide_h(this, ['content1'], -1 * wx.system.width, 0, () => {
        wx.slide_h(this, ['content1'], 0, 1, 0);
      });
    });
  },
  
  cardTap(e) {
    wx.modal('', modal[wx.lang].choose0, modal[wx.lang].choose1, modal[wx.lang].choose2,
    null, null, () => {
      if (sending++) return;
      wx.post('PracticeItem.chooseReceiver', { idPracticeItem: e.currentTarget.id }, () => {
        wx.toast(modal[wx.lang].succ, 1);
        setTimeout(() => {
          wx.onHide(this, 1, null, null, () => {
            sending = 0;
          });
        }, 1000)
      }, text[wx.lang].sending)
  
    })
  },

  onShareAppMessage: function () {
    return wx.onShareAppMessage();
  }
})